<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<?php include "../public/header_main.php";?>
<style>
    .laytp-container #table-card{padding: 0!important;}
    #mainnav{padding-bottom: 0!important;}
    .left_but{padding: 10px 0 10px 15px;border-bottom: 1px solid #d1d1d1}
    .layui-card{padding-bottom: 0;margin-bottom: 0}
    .layui-table-tool-temp{padding-right:0 }
    .layui-table tr {
        height: unset !important;
        line-height: unset !important;
    }
    .qingbgclr{background-color: #666666;color: #FFFFFF}
    .opTable-open-td tr:hover{background-color: #666!important;color: #FFFFFF!important;}
</style>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title" id="titss"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<?php include "dao.php"?>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md2">
                <div class="layui-card-body">
                    <table id="datalist_nav" lay-filter="datalist_nav"></table>
                </div>
            </div>


            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo_nav">
    <div class = "layui-btn-container">
        <button class="layui-btn layui-btn-primary outbut" style="width: 60px;" onclick="auth_but_func_import('导入')">导入</button>
        <button class="layui-btn layui-btn-primary outbut" style="width: 60px;" onclick="auth_but_func_guan('管理')">管理</button>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_basel()">生成基底清单</button>
<!--        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_export()">导出清单为Excel</button>-->
        <button class="layui-btn layui-btn-primary outbut qingEditOpt layui-hide" onclick="auth_but_func_addqinghang()">新增清单行</button>
        <button class="layui-btn layui-btn-primary outbut qingEditOpt layui-hide" onclick="auth_but_func_editqinghang()">编辑清单行</button>
        <button class="layui-btn layui-btn-primary outbut qingEditOpt layui-hide" onclick="auth_but_func_delqinghang()">删除清单行</button>
        <div class="biantit" style="color: #248bfe;font-size: 13px;float: right;margin-right: 100px"></div>
    </div>
</script>

<script type="text/javascript">

    var top_qingid = '';
    var edit_qingid = 0;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        table.render({
            elem: "#datalist_nav",id: "datalist_nav"
            ,url: facade.url(ask_main_qing_list),where: {enginid:param_enginid}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: '#toolbarDemo_nav', overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data
                };
            }
            ,cols: [[
                {field:'qingname',title:'分部名称'}
            ]]
            ,done : function(res, curr, count){
                soulTable.render(this);
                $("#layui-table-page1").remove();
            }
        });


        //监听行单击事件
        table.on('row(datalist_nav)', function(obj){
            $(obj.tr).parent().find('tr').attr("style","background:#ffffff!important;color:#666")
            $(obj.tr).attr("style","background:#248BFE!important;color:#FFFFFF")
            var keyword = $('#keyword').val();
            var qingid = obj.data.id;
            top_qingid = obj.data.id;
            table.reload('datalist', {
                page:{curr:1},
                where: {
                    keyword:keyword,
                    qingid:qingid,
                    enginid:param_enginid,
                }
            });
        });






        layui.config({
            base: '../../static/component/lib/opTable'
        }).extend({
            opTable: '/opTable'
        }).use(['opTable'],function() {
            var opTable = layui.opTable.render({
                elem: '#datalist'
                ,toolbar: TabInit.toolbar
                ,method:TabInit.method
                ,defaultToolbar: ['filter', '', 'print']
                ,height: 'full-102'
                ,url: server_api_name+ask_main_qingnav_list
                ,page: false
                ,openType: 1
                ,request: {pageName: 'page',limitName: 'pagesize'}
                ,where:{enginid:param_enginid}
                ,parseData: function(res){
                    $(".biantit").html(res.data.tit);

                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.total,
                        "data": res.data.data
                    };
                }
                ,response: {statusCode: 2000}
                ,cols: [[
                    {field:'encode',title:'项目编码'}
                    ,{field:'enname',title:'项目名称',templet: function(d){return '<span class="iszi" id="'+d.id+'" key="'+d.iszi+'">'+d.enname+'</span>';},width:300}
                    ,{field:'enfeat',title:'项目特征描述',width:400}
                    ,{field:'enunit',title:'计量单位',width:100}
                    ,{field:'enword',title:'工程量',width:150}
                    ,{field:'renprice',title:'人工费(元)',width:150}
                    ,{field:'caiprice',title:'材料费(元)',width:150}
                    ,{field:'jiprice',title:'机械费(元)',width:150}
                    ,{field:'fenprice',title:'专业分包(元)',width:150}
                    ,{field:'price',title:'综合成本单价(元)',width:150}
                    ,{field:'money',title:'综合成本合计(元)',width:150}
                    ,{field:'renfee_cur',title:'人工费合计(元)',width:150}
                    ,{field:'caifee_cur',title:'材料费合计(元)',width:150}
                    ,{field:'jifee_cur',title:'机械费合计(元)',width:150}
                    ,{field:'fenfee_cur',title:'专业分包合计(元)',width:150}
                ]]
                ,done: function(res, curr, count){
                    // $("#opTableZhanAll").click();
                    // $('div[lay-id="datalist"]').find('td').mouseover(function () {
                    //     $(this).parent().find('td').each(function () {
                    //         $(this).css('cssText','background-color: #e7ecf5 !important;');
                    //     })
                    // });



                    $('div[lay-id="datalist"] .layui-table-header thead>tr>th:first-child').find('.layui-table-sort').remove();
                }
                , openTable: function (itemData) {
                    var elemId = 'child_1_' + itemData.LAY_INDEX;
                    return {
                        elem: '#child_1_' + itemData.LAY_INDEX
                        , id: elemId
                        ,method:'post'
                        ,url: server_api_name+ask_main_qinglist_list
                        ,page: false
                        ,where:{enginid:param_enginid,fenname:itemData.enname,qingid:top_qingid}
                        ,parseData: function(res){
                            return {
                                "code": res.code,
                                "msg": res.message,
                                "count": res.data.total,
                                "data": res.data.data
                            };
                        }
                        ,response: {statusCode: 2000}
                        ,cols: [[
                            {field:'encode',title:'项目编码'}
                            ,{field:'enname',title:'项目名称',templet: function(d){return '<span class="iszi" id="'+d.id+'" key="'+d.iszi+'">'+d.enname+'</span>';},width:300}
                            ,{field:'enfeat',title:'项目特征描述',width:400}
                            ,{field:'enunit',title:'计量单位',width:100}
                            ,{field:'enword',title:'工程量',width:150, edit:'text'}
                            ,{field:'renprice',title:'人工费(元)',width:150}
                            ,{field:'caiprice',title:'材料费(元)',width:150}
                            ,{field:'jiprice',title:'机械费(元)',width:150}
                            ,{field:'fenprice',title:'专业分包(元)',width:150}
                            ,{field:'price',title:'综合成本单价(元)',width:150}
                            ,{field:'money',title:'综合成本合计(元)',width:150}
                            ,{field:'renfee_cur',title:'人工费合计(元)',width:150}
                            ,{field:'caifee_cur',title:'材料费合计(元)',width:150}
                            ,{field:'jifee_cur',title:'机械费合计(元)',width:150}
                            ,{field:'fenfee_cur',title:'专业分包合计(元)',width:150}
                        ]]
                        ,done: function(res, curr, count){
                            $(".opTable-open-td").find('th').hide();
                            // $(".opTable-open-td").find('td').css('cssText','background-color: #deeafd !important;');
                            // $(".opTable-open-td").find('td').mouseover(function () {
                            //     $(this).parent().find('td').each(function () {
                            //         $(this).css('cssText','background-color: #e7ecf5 !important;');
                            //     })
                            // });
                            // $(".opTable-open-td").find('td').mouseout(function () {
                            //     $(this).parent().find('td').each(function () {
                            //         $(this).css('cssText','background-color: #deeafd !important;');
                            //     })
                            // });


                        }
                        , openTable: function (itemData) {
                            var elemId = 'child_2_' + itemData.LAY_INDEX;
                            return {
                                elem: '#child_2_' + itemData.LAY_INDEX
                                , id: 'child_2_' + itemData.LAY_INDEX
                                ,method:'post'
                                ,url: server_api_name+ask_main_qinglist_list
                                ,page: false
                                ,where:{enginid:param_enginid,fenname:itemData.fenname,ziname:itemData.enname,qingid:itemData.qingid}
                                ,parseData: function(res){
                                    return {
                                        "code": res.code,
                                        "msg": res.message,
                                        "count": res.data.total,
                                        "data": res.data.data
                                    };
                                }
                                ,response: {statusCode: 2000}
                                ,cols: [[
                                    {field:'encode',title:'项目编码'}
                                    ,{field:'enname',title:'项目名称',templet: function(d){return '<span class="iszi" id="'+d.id+'" key="'+d.iszi+'">'+d.enname+'</span>';},width:300}
                                    ,{field:'enfeat',title:'项目特征描述',width:400}
                                    ,{field:'enunit',title:'计量单位',width:100}
                                    ,{field:'enword',title:'工程量',width:150}
                                    ,{field:'dan_ren',title:'人工费(元)',width:150}
                                    ,{field:'dan_cai',title:'材料费(元)',width:150}
                                    ,{field:'dan_ji',title:'机械费(元)',width:150}
                                    ,{field:'dan_zhuan',title:'专业分包(元)',width:150}
                                    ,{field:'dan_zong',title:'综合成本单价(元)',width:150}
                                    ,{field:'fee_zong',title:'综合成本合计(元)',width:150}
                                    ,{field:'fee_ren',title:'人工费合计(元)',width:150}
                                    ,{field:'fee_cai',title:'材料费合计(元)',width:150}
                                    ,{field:'fee_ji',title:'机械费合计(元)',width:150}
                                    ,{field:'fee_zhuan',title:'专业分包合计(元)',width:150}
                                ]]
                                ,done: function(res, curr, count){
                                    $(".opTable-open-td").find('th').hide();


                                }
                            }
                        }
                    }
                }
            });
        });


        $('body').on('click','.opTable-open-td td',function () {
            var iszi = $(this).parent('tr').find('td[data-field="enname"] div .iszi').attr('key');
            if(parseInt(iszi) == 0){
                edit_qingid = $(this).parent('tr').find('td[data-field="enname"] div .iszi').attr('id') || 0;
                $('.opTable-open-td tr').removeClass('qingbgclr');
                $(this).parent('tr').addClass('qingbgclr');

                if(parseInt(top_qingid) > 0){
                    $(".qingEditOpt").removeClass('layui-hide');
                }
            }
            return false;
        })


        listTableSearch(form, table);
    });



    function auth_but_func_import(buttitle, index){
        openPage('qing_add.php?close=1&enginid='+param_enginid, '80%','80%');
    }
    function auth_but_func_guan(buttitle, index){
        openPage('qing_guan.php?close=1&enginid='+param_enginid, '80%','80%');
    }

    function auth_but_func_addqinghang() {
        top_qingid = parseInt(top_qingid) || 0;
        if(parseInt(top_qingid) < 1){
            facade.error('请选择左侧分部名称');return false;
        }
        edit_qingid = parseInt(edit_qingid) || 0;
        if(edit_qingid < 1){
            facade.error('请选择清单行数据');return false;
        }
        openPageEdit('qing_addhang.php?close=1&id='+edit_qingid, '80%', '80%');
    }
    function auth_but_func_editqinghang() {
        top_qingid = parseInt(top_qingid) || 0;
        if(parseInt(top_qingid) < 1){
            facade.error('请选择左侧分部名称');return false;
        }
        edit_qingid = parseInt(edit_qingid) || 0;
        if(edit_qingid < 1){
            facade.error('请选择清单行数据');return false;
        }
        openPageEdit('qing_edithang.php?close=1&id='+edit_qingid, '80%', '80%');
    }
    function auth_but_func_delqinghang() {
        top_qingid = parseInt(top_qingid) || 0;
        if(parseInt(top_qingid) < 1){
            facade.error('请选择左侧分部名称');return false;
        }
        edit_qingid = parseInt(edit_qingid) || 0;
        if(edit_qingid < 1){
            facade.error('请选择清单行数据');return false;
        }
        data_delete(ask_main_qing_delhang, {id:edit_qingid});
    }


    function auth_but_func_basel() {
        facade.ajax({url: ask_main_basal_add, data:{enginid:param_enginid}}).done(function(res){
            if (res.code === 2000) {
                facade.success("操作成功!");
            }
        });
    }
    function auth_but_func_export() {
        facade.ajax({url: ask_main_qing_export, data:{id:param_enginid}}).done(function(res){
            if (res.code === 2000) {
                facade.success("导出成功");
                let btnDownload = document.createElement('a'),
                    clickEvent = document.createEvent("MouseEvent");
                let url = server_api_name + "/" + res.data;
                clickEvent.initEvent("click", true, false);
                btnDownload.setAttribute("href", url);
                btnDownload.setAttribute("target", '_blank');
                btnDownload.dispatchEvent(clickEvent);
            }
        });
    }

</script>
</body>
</html>
